#ifndef __PCF8574_H__
#define __PCF8574_H__
#include "my_include.h"

#define PCF8574_EN         0   //启动扩展芯片  

extern u8 PCF8574_Timer;

#define PCF8574_SCL        PBout(6) 
#define PCF8574_SDA        PBout(7)    
#define PCF8574_SDA_DataIN PBin(7)

#define PCF8574_SDA_IN              {GPIOB->CRL&=0X0FFFFFFF;GPIOB->CRL|=(u32)8<<28;}
#define PCF8574_SDA_OUT             {GPIOB->CRL&=0X0FFFFFFF;GPIOB->CRL|=(u32)3<<28;}  


#define PCF8574A_write  0x40
#define PCF8574A_read   0x41
#define PCF8574B_write  0x4E
#define PCF8574B_read   0x4F
#define PCF8574C_write  0x4C
#define PCF8574C_read   0x4D
#define PCF8574D_write  0x48
#define PCF8574D_read   0x49

//#define CAMERA1(s)   ControlPin(PCF8574A_write,1,s);
//#define CAMERA2(s)   ControlPin(PCF8574A_write,2,s);
//#define CAMERA3(s)   ControlPin(PCF8574A_write,3,s);
//#define CAMERA4(s)   ControlPin(PCF8574A_write,4,s);
//#define POWER_12V(s) ControlPin(PCF8574A_write,5,s);


//#define Relay6(s) ControlPin(PCF8574A_write,6,s);
//#define Relay7(s) ControlPin(PCF8574A_write,7,s);
//#define Relay8(s) ControlPin(PCF8574A_write,8,s);
    
#define ReadPCF8574A PCF8574_Read(PCF8574A_read)
#define ReadPCF8574B PCF8574_Read(PCF8574B_read)
#define ReadPCF8574C PCF8574_Read(PCF8574C_read)
#define ReadPCF8574D PCF8574_Read(PCF8574D_read)


#define CAMERA1Status   ((ReadPCF8574A&0x01)>>0)
#define CAMERA2Status   ((ReadPCF8574A&0x02)>>1)
#define CAMERA3Status   ((ReadPCF8574A&0x04)>>2)
#define CAMERA4Status   ((ReadPCF8574A&0x08)>>3)
#define POWER12VStatus  ((ReadPCF8574A&0x10)>>4)

#define RelayFlg6 ((ReadPCF8574A&0x20)>>5)
#define RelayFlg7 ((ReadPCF8574A&0x40)>>6)
#define RelayFlg8 ((ReadPCF8574A&0x80)>>7)

//*****************新动环扩展引脚定义***********************//

#define LIGHTING(s)        ControlPin(PCF8574A_write,1,s);    //照明灯输出
#define FIRELINKAGE(s)     ControlPin(PCF8574A_write,2,s);    //消防联动输出

#define LIGHTINGStatus      ((ReadPCF8574A&0x01)>>0)    //照明灯输出 状态
#define FIRELINKAGEStatus   ((ReadPCF8574A&0x02)>>1)    //消防联动输出 状态

#define SMOKEStatus         ((ReadPCF8574A&0x04)>>2)    //烟雾传感器
#define WATERStatus         ((ReadPCF8574A&0x08)>>3)    //水浸传感器
#define INFRAEDStatus       ((ReadPCF8574A&0x10)>>4)    //红外传感器

#define DOOR1Status         ((ReadPCF8574A&0x20)>>5)    // 门磁1
#define DOOR2Status         ((ReadPCF8574A&0x40)>>6)    // 门磁2
#define ACCESSStatus        ((ReadPCF8574A&0x80)>>7)    // 门禁


#define NoEquipment          0x01     //空载
#define EquipmentWork        0x02     //工作
#define EquipmentAberrancy   0x03     //异常
#define StandbyEquipment     0x04     //待机
#define NoPowerSupply        0x05     //无电源接入
#define PowerSupplyAberrancy 0x06     //电源异常

void Init_PCF8574(void);
u8 PCF8574_Read(u8 PCF8574TS);
u8 PCF8574_Write(u8 PCF8574TS,u8 data);
void ControlPin(u8 add,u8 pin,u8 onoff);
void Pcf8574_Control_Pin(u8 add,u8 pin,u8 onoff);
#endif
